package org.zerta.troops.common;

import java.awt.Point;
import java.util.Map;
import java.util.HashMap;

/** 
 * Holds all information about a single area.
 */
public class Area {

	private String name;
	private Player owner;
	private Army ownerArmy;
	private Map<String,Area> neighbors;
	private Point position;
	private Map<String,Army> currentArmies;
	
	public Area () {
		neighbors = new HashMap<String, Area>();
		currentArmies = new HashMap<String, Army>();
	}
	
	public void setName(String name) {
		this.name = name;
	}

	public String getName() {
		return name;
	}
	
	public void setOwner( Player player ) {
		owner = player;
	}
	
	public Player getOwner() {
		return owner;
	}
	
	public void setOwnerArmy( Army army ) {
		ownerArmy = army;
	}
	
	public Army getOwnerArmy() {
		return ownerArmy;
	}

	public Map<String, Area> getNeighbors() {
		return neighbors;
	}

	public void addNeighbor( Area neighbor ) {
		neighbors.put(neighbor.getName().toLowerCase(), neighbor);
	}
	
	public boolean hasNeighbor( Area neighbor ) {
		return neighbors.containsKey(neighbor.getName().toLowerCase());
	}
	
	public Point getPosition() {
		return position;
	}

	public void setPosition(Point position) {
		this.position = position;
	}
	
	public void addCurrentArmy( Army army ) {
		currentArmies.put(army.getOwner().getName().toLowerCase(), army);
	}
	
	public void clearCurrentArmies() {
		currentArmies.clear();
	}
	
	public Map<String, Army> getCurrentArmies() {
		return currentArmies;
	}
	
	public Army getCurrentArmyForPlayer( Player player ) {
		if (currentArmies.containsKey(player.getName().toLowerCase())) {
			return currentArmies.get(player.getName().toLowerCase());
		} else {
			return null;
		}
	}
	
}
